/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "frm_control_TStringEdit.h"

using namespace frm;
using namespace control;

// TStringEdit ////////////////////////////////////////////////////////////////////

//
TStringEdit::TStringEdit(TWindow &Window,int MaxLen) : TString(Window)
{ 
  maxLen = MaxLen;
  enableEdit = true;
}

//
void TStringEdit::SetValue(svl::TVariant V) 
{ 
  if (V.IsNull()) 
    { SetNull(); } 
  else 
    { TString::SetValue(V.String()); } 
}

//
bool TStringEdit::UpdateValue(svl::TString V)
{
  if (maxLen > 0 && V.Len() < maxLen)
    { return TString::UpdateValue(V);}
  else if (maxLen == 0)
    { return TString::UpdateValue(V);}
  return false;
}

//
void TStringEdit::TComponent_KeyboardKey(grf::TKeyboardKey &KeyboardKey)
{
  if (enableEdit)
    { TString::TComponent_KeyboardKey(KeyboardKey);}
  else switch (KeyboardKey.Key)
  {
    case VK_RIGHT: case VK_LEFT: case VK_HOME: case VK_END:
      TString::TComponent_KeyboardKey(KeyboardKey);
    break;

    default: TPanel::TComponent_KeyboardKey(KeyboardKey);
  }
}

//
void TStringEdit::TComponent_KeyboardChar(grf::TKeyboardChar &KeyboardChar)
{
  if (enableEdit)
    { TString::TComponent_KeyboardChar(KeyboardChar);}
  else
    { TPanel::TComponent_KeyboardChar(KeyboardChar);}
}
